﻿function Framework() {
    return {
        Account:
        {
            _currentUser: null,
            setCurrentUser: function(user) {
                this._currentUser = user;
            },
            getCurrentUser: function() {
                return this._currentUser;
            }
        },
        Page:
        {
            Parameters:
            {
                getQueryStringParameters: function() {
                    var params = new Object();
                    var searchParams = window.location.search.replace('?', '');
                    if (searchParams.length > 0) {
                        var arrSearch = searchParams.split('&');
                        for (var i = 0; i < arrSearch.length; i++) {
                            var prop = arrSearch[i].substring(0, arrSearch[i].indexOf('='));
                            var value = arrSearch[i].substring(arrSearch[i].indexOf('=') + 1);
                            params[prop] = value;
                        }
                    }
                    return params;
                },
                parseQueryString: function () {
                    var params = Framework.Page.Parameters.getQueryStringParameters();
                    var keys = Object.keys(params);
                    for (var i = 0; i < keys.length; i++) {
                        this[keys[i]] = params[keys[i]];
                    }
                },
            }
        },
        Effects:
        {
            scrollTo: function(element, containerId, delay) {
                var _containerId = containerId != null ? containerId : "html, body";
                $(_containerId).animate({ scrollTop: element.offset().top }, delay != null ? delay : 2000);
            }
        },
        Handlers:
        {
            EventTypes : { Click: "click", KeyUp: "keyup" },
            getAllHandlers: function(idElement)
            {
                var htmlElement = $("#" + idElement)[0];
                // http://api.jquery.com/data/
                return $._data(htmlElement, "events");
            },
            removeHandlers: function(elements, event)
            {
                // http://api.jquery.com/off/
                elements.off(event);
            },
            onClick: function (elements, fnAction, fnActionEventData)
            {
                $.each(elements, function (key, value)
                {
                    Framework.Handlers.removeHandlers($("#" + value.id), Framework.Handlers.EventTypes.Click);
                    // http://api.jquery.com/on/
                    // http://api.jquery.com/event.data/
                    var events = Framework.Handlers.EventTypes.Click;
                    var selector = null;
                    var data = fnActionEventData;
                    var handler = fnAction;
                    $("#" + value.id).on(events, selector, data, handler);
                });
            }
        }
    }
}